﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Project08
{
    class Grid
    {
        private VertexBuffer vertexBuffer;
        private List<VertexPositionColor> vertices;

        public Grid()
        {
            vertices = new List<VertexPositionColor>();
        }

        public void LoadVertices()
        {
            //X Axis
            vertices.Add(new VertexPositionColor(new Vector3(-400, 0, -200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(400, 0, -200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(-400, 0, -100), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(400, 0, -100), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(-400, 0, 0), Color.White));
            vertices.Add(new VertexPositionColor(new Vector3(400, 0, 0), Color.White));
            vertices.Add(new VertexPositionColor(new Vector3(-400, 0, 100), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(400, 0, 100), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(-400, 0, 200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(400, 0, 200), Color.Black));

            //Y Axis
            vertices.Add(new VertexPositionColor(new Vector3(0, 0, 0), Color.White));
            vertices.Add(new VertexPositionColor(new Vector3(0, 400, 0), Color.White));

            //Z Axis
            vertices.Add(new VertexPositionColor(new Vector3(-400, 0, 200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(-400, 0, -200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(-300, 0, 200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(-300, 0, -200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(-200, 0, 200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(-200, 0, -200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(-100, 0, 200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(-100, 0, -200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(0, 0, 200), Color.White));
            vertices.Add(new VertexPositionColor(new Vector3(0, 0, -200), Color.White));
            vertices.Add(new VertexPositionColor(new Vector3(100, 0, 200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(100, 0, -200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(200, 0, 200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(200, 0, -200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(300, 0, 200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(300, 0, -200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(400, 0, 200), Color.Black));
            vertices.Add(new VertexPositionColor(new Vector3(400, 0, -200), Color.Black));
        }

        public void Draw(GraphicsDevice graphicsDevice, BasicEffect basicEffect)
        {
            vertexBuffer = new VertexBuffer(graphicsDevice, typeof(VertexPositionColor),
                vertices.Count, BufferUsage.WriteOnly);
            vertexBuffer.SetData<VertexPositionColor>(vertices.ToArray());

            graphicsDevice.SetVertexBuffer(vertexBuffer);

            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawPrimitives(PrimitiveType.LineList, 0, 15);
            }
        }
    }
}
